<?php
/** Drug_list 
	* 
	* @package Pharmacy Intervention 
	* @subpackage Controller
	* @category Drug 
	* @author Ray Nowell */  
class Drug_list  extends MY_Controller {
  
  function Drug_list()
  {
    parent::MY_Controller(MUST_BE_ADMIN);
  }
  
  function index()
  {
		//$this->output->enable_profiler(TRUE);  
		
		define("POPUP_HEIGHT", 550);
		define("POPUP_WIDTH", 550);
		define("DRUG_LIST_PAGE_SEGMENT", 3);  //Determines segment to determine which page to browse the results. 
		
		$this->load->helper('form');
		$this->load->helper('cookie');
		$this->load->helper('date');
				
		$data['title'] = COMPANY_NAME.' -- Drug List';
		$data['heading'] = 'Drugs';		
		
		$auto_add 		=	$this->session->flashdata('auto_add');
		$auto_add_js	=	$auto_add ? '$(\'#_gridAddTop\').click();' : '';
		$data['additional_javascript_doc_ready_functions'] = get_grid_doc_ready_javascript();
		$data['additional_jquery_javascript'] = get_grid_functions('drug', POPUP_HEIGHT, POPUP_WIDTH);
		
		$data['add_link'] = '<input id="_gridAddTop" type="image" border="0" language="javascript" onclick="return false;" alt="Insert" title="Insert" src="'.base_url().'images/add.png"  style="cursor: pointer;"/>';
		$data['view_link'] = '<input class="GridButton" id="_gridViewTop" type="image" disabled="disabled" border="0" language="javascript" onclick="return false;" alt="View" title="View" src="'.base_url().'images/view_disabled.png"  style="cursor: pointer;"/>';
		$data['copy_link'] = '<input class="GridButton" id="_gridCopyTop" type="image" disabled="disabled" border="0" language="javascript" onclick="return false;" alt="Copy" title="Copy" src="'.base_url().'images/copy_disabled.png"  style="cursor: pointer;"/>';
		$data['delete_link'] = '<input class="GridButton" id="_gridDeleteTop" type="image" disabled="disabled" border="0" language="javascript" onclick="return false;" alt="Delete" title="Delete" src="'.base_url().'images/delete_disabled.png"  style="cursor: pointer;"/>';

		$this->load->library('table');
		$this->table->set_heading('<input type="checkbox" id="_chkMaster">','Item','Generic','size code','size qty','strength code','strength qty','nddf awp','nddf ndc number','nddf package size qty','pack size','wholesale cost','wholesale each cost','doses per day');
		
		$this->load->model('Drug_model');
		
		
		
		//$this->output->enable_profiler(TRUE);
		$passed_page	=	$this->uri->segment(DRUG_LIST_PAGE_SEGMENT);
		$passed_page	=	$passed_page == false ? 1 : $passed_page;
		
		$drug_array = $this->Drug_model->get_drug_list($passed_page);
		
		//loop through the results and checkbox the id
		foreach($drug_array  as $row)
		{
			$java_script_text  = 'popup_edit_single('.$row['drug_id'].');return false;'; //Must do this before replacing text on line below
			$row['drug_id']= '<input class="GridCheckbox" type="checkbox" name="_chkDrug'.$row['drug_id'].'" >';
	 				$edit_link_atts = array('title' 	=>	'Edit',
											'onclick'	=>	$java_script_text 
											);
			$row['item_desc'] = anchor('requirements',$row['item_desc'],$edit_link_atts);			 	
			 
			 $this->table->add_row($row);
		}
		
		$local_table_template = set_table_template();
		$this->table->set_template($local_table_template); 
		$local_table	=	$this->table->generate();
		$local_table	=	str_replace('<td><input class="GridCheckbox"','<td class="GridCheckboxTd"><input class="GridCheckbox"',$local_table);
		$local_table	=	str_replace('<td>class="savings-cell"-negative','<td class="savings-cell-negative">',$local_table);
		$local_table	=	str_replace('<td>class="savings-cell"','<td class="savings-cell">',$local_table);
		
		$data['drug_list']	=	$local_table;
		
		//Check flash data to see if there is any text to display to the user 
		$deleted_info = $this->session->flashdata('deleted_info');
		if (!empty($deleted_info))
			$data['deleted_info']	=	$deleted_info;
			
		$this->load->library('pagination');
		
		$drug_count	=	$this->db->count_all_results('drug_list');

		$config['base_url'] = base_url().'index.php/drug_list/page/';
		$config['total_rows'] = $drug_count;
		$config['per_page'] = '10';

		$this->pagination->initialize($config);

		$data['page_links']	=	$this->pagination->create_links();
		
		$data['view'] = 'drug_list_view';
		$this->load->vars($data);
		$this->load->view('master_view', $data);  
  }
  
  function page()
  {
  	define("DRUG_LIST_PAGE_SEGMENT", 3);  //Determines segment to determine which page to browse the results.
  	$new_page	=	$this->uri->segment(DRUG_LIST_PAGE_SEGMENT);
 	redirect('drug_list/index/'.$new_page);
  }
}  
/* End of file drug_list.php */
/* Location: ./system/application/controllers/drug_list.php */
